from core.support import set_cutscene, get_game
from core.item import Item
from core.action import Action
from items.BU_ID import BU_ID

class ID5(Item):
    def __init__(self):
        Item.__init__(self, "id5")    # do basic initialization for every item
        self.wholeId = False
        
        # build list of actions
        self.add_action(PutIDTogether)
    
    def get_description(self):
        return "ID5"
    
    def get_image(self):
        return "ID_piece5.jpg"

# define actions for this item

class PutIDTogether(Action):
    def __init__(self):
        Action.__init__(self, "put_id_together")    # do basic initialization for every action
        self.isItemAction=True
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Put Your ID Together"
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
    
    def do_action(self,game,room,request):
        set_cutscene("Congratulations! You have collected all the pieces of your ID and put them together.")
        self.item.wholeId = True
        game = get_game()
        player = game.get_player()
        player.pop_item('id1')
        player.pop_item('id2')
        player.pop_item('id3')
        player.pop_item('id4')
        player.pop_item('id5')
        player.add_item(BU_ID())
        return
    
    def is_enabled(self):
        game = get_game()
        player = game.get_player()
        if not self.item.wholeId:
            if 'id1' in player.inventory and 'id2' in player.inventory and 'id3' in player.inventory and 'id4' in player.inventory:
                return True
        return False
